package com.ruoyi.api.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Yuan
 * @date 2022/2/18 下午4:41
 */

@Slf4j
public class ParseUtils {

    public static String parseGeom(Integer type, String coordinate) {
        String[] split = coordinate.split(",");
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < split.length; i++) {
            stringBuffer.append(split[i]);
            if (i % 2 == 1 && i != split.length - 1) {
                stringBuffer.append(",");
            }
            if (i != split.length - 1) {
                stringBuffer.append(" ");
            }
        }
        String geom = null;
        if (type == 0) {
            geom = "POINT(" + stringBuffer + ")";
        }
        if (type == 1) {
            geom = "LINESTRING(" + stringBuffer + ")";
        }
        if (type == 2) {
            geom = "POLYGON((" + stringBuffer   + "))";
        }
        return geom;
    }



    public static String parseEvadeInfo(Integer type, String[] coordinate) {

        StringBuffer stringBuffer = new StringBuffer();

        if (type.equals("POINT")) {
            stringBuffer.append("0,");
            for (int j = 0; j < coordinate.length; j++) {
                stringBuffer.append(coordinate[j]);
                if (j != coordinate.length - 1) {
                    stringBuffer.append(",");
                }
            }
        }
        if (type.equals("LINESTRING")) {
            stringBuffer.append("1,");
            for (int j = 0; j < coordinate.length; j++) {
                stringBuffer.append(coordinate[j]);
                if (j != coordinate.length - 1) {
                    stringBuffer.append(",");
                }
            }
        }
        if (type.equals("POLYGON")) {
            stringBuffer.append("2,");
            for (int j = 0; j < coordinate.length - 2; j++) {
                stringBuffer.append(coordinate[j]);
                if (j != coordinate.length - 3) {
                    stringBuffer.append(",");
                }
            }
        }

        return stringBuffer.toString();
    }

    public static String parseBroadcastType(String str) {
//        if(str.contains("RoadState")){
//            String roadState = str.replace("RoadState", "");
//            String type = str.replaceAll("[\\d\\s.,()]", "");
//
//            String newStr = str.replaceAll("[a-zA-Z(),]", "");
//            String[] coordinate = newStr.split(" ");
//        }
        if (str.equals("RS")) {
            return "前方有一条新的道路信息";
        }
        if (str.equals("TS")) {
            return "前方有一条新的交通路况";
        }
        if (str.equals("DA")) {
            return "前方出现新的危险区域";
        }
        if (str.equals("TE")) {
            return "前方出现突发事件";
        }
        if (str.equals("EI")) {
            return "前方有一条新的DQ信息";
        }
        if (str.equals("SD")) {
            return "前方有一条新的专题数据";
        }
        if (str.equals("TQ")) {
            return "前方有一条新的天气信息";
        }
        return null;
    }
}
